package com.example.project.business.aop_demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SomeService {

	private SomeInnerService someInnerService;

//	@Autowired
//	内部类注入外部类，产生循环依赖问题（内部类持有外部类对象的引用）
//	org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'someService': 
//	Bean with name 'someService' has been injected into other beans [initInnerSerice] in its raw version as part of a circular reference, 
//	but has eventually been wrapped. 
//	This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
	public void setInnerService(SomeInnerService i) {
		this.someInnerService = i;
	}
	
	SomeService() {
		super();
	}

	@Bean
	public SomeInnerService initInnerSerice() {
		SomeInnerService someInnerService = this.new SomeInnerService();
		System.out.println(this + " new InnerService " + someInnerService);
		return someInnerService;
	}

	public void print() {
		System.out.println(Thread.currentThread() + " SomeService print  innerService " + someInnerService);
	}

	@Async
	public void printAsync() {
		System.out.println(Thread.currentThread() + " SomeService Async print ");
	}

	@Transactional
	@Async(value = "async-executor")
//	@Retryable
	public void printTransaction() {
		System.out.print(" Transactional ");
		this.print();
	}

	class SomeInnerService {

	}
}
